#include <iostream>
#include <pthread.h>



//封装锁
namespace MyMutexArea
{
    class MyMutex
    {
    public:
    MyMutex()
    {
        int n1 = ::pthread_mutex_init(&_mutex,nullptr);
        if(n1!=0)
        {
            std::cerr<<"pthread_mutex_init error"<<std::endl;
            exit(1);
        }
    }

    void Lock()
    {
        int n = ::pthread_mutex_lock(&_mutex);
        if(n!=0)
        {
            std::cerr<<"pthread_mutex_lock error"<<std::endl;
            return;
        }
    }

    void Unlock()
    {
        int n = ::pthread_mutex_unlock(&_mutex);
        if(n!=0)
        {
            std::cerr<<"pthread_mutex_unlock error"<<std::endl;
            return;
        }
    }

    ~MyMutex()
    {
        int n = ::pthread_mutex_destroy(&_mutex);
        if(n!=0)
        {
            std::cerr<<"pthread_mutex_destroy error"<<std::endl;
            exit(4);
        }
    }

    private:
        pthread_mutex_t _mutex;
    };
};